package com.lonwin.inspectionmanagement.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.lonwin.inspectionmanagement.mvp.contract.CruiseLocusContract;
import com.lonwin.inspectionmanagement.mvp.model.api.service.BusinessService;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.DelLocusBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.HistoryRecordingBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.NeatentLocusBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.OpenLocusBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.PatrolBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.QuestListBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.SearLocusBean;

import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.functions.Function;


@ActivityScope
public class CruiseLocusModel extends BaseModel implements CruiseLocusContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public CruiseLocusModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<HistoryRecordingBean> queryHistory(String url, Map<String,String> maps) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).queryHistory(url,maps)
                .map(new Function<HistoryRecordingBean, HistoryRecordingBean>() {
                    @Override
                    public HistoryRecordingBean apply(HistoryRecordingBean historyRecordingBean) throws Exception {
                        return historyRecordingBean;
                    }
                });
    }

    @Override
    public Observable<PatrolBean> getXcpath(String url, Map<String, String> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).getXcpath(url,params)
                .map(new Function<PatrolBean, PatrolBean>() {
                    @Override
                    public PatrolBean apply(PatrolBean patrolBean) throws Exception {
                        return patrolBean;
                    }
                });
    }

    @Override
    public Observable<SearLocusBean> getXcpathTemp(String url, Map<String, Object> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).getXcpathTemp(url,params).map(new Function<SearLocusBean, SearLocusBean>() {
            @Override
            public SearLocusBean apply(SearLocusBean searLocusBean) throws Exception {
                return searLocusBean;
            }
        });
    }

    @Override
    public Observable<NeatentLocusBean> neatenXcpathTemp(String url, Map<String, String> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).neatenXcpathTemp(url,params)
                .map(new Function<NeatentLocusBean, NeatentLocusBean>() {
                    @Override
                    public NeatentLocusBean apply(NeatentLocusBean neatentLocusBean) throws Exception {
                        return neatentLocusBean;
                    }
                });
    }

    @Override
    public Observable<OpenLocusBean> openXcpathTemp(String url, Map<String, Object> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).openXcpathTemp(url,params)
                .map(new Function<OpenLocusBean, OpenLocusBean>() {
                    @Override
                    public OpenLocusBean apply(OpenLocusBean openLocusBean) throws Exception {
                        return openLocusBean;
                    }
                });
    }

    @Override
    public Observable<DelLocusBean> deleteXcpathTemp(String url, Map<String, Object> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).deleteXcpathTemp(url,params)
                .map(new Function<DelLocusBean, DelLocusBean>() {
                    @Override
                    public DelLocusBean apply(DelLocusBean delLocusBean) throws Exception {
                        return delLocusBean;
                    }
                });
    }

    @Override
    public Observable<QuestListBean> getGcglQuestTemp(String url, Map<String, Object> params) {
        return mRepositoryManager.obtainRetrofitService(BusinessService.class).getGcglQuestTemp(url,params)
                .map(new Function<QuestListBean, QuestListBean>() {
                    @Override
                    public QuestListBean apply(QuestListBean questListBean) throws Exception {
                        return questListBean;
                    }
                });
    }
}